<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>钻石投票系统管理后台</title>
    <link rel="stylesheet" href="__CSS__/font-awesome.css"/>
    <link rel="stylesheet" href="__MCSS__/bass.css"/>
    <link rel="stylesheet" href="__MCSS__/admin-set.css"/>
</head>
<body>

<div class="admin-set">
    <div class="main">

        <p class="admin-set-tit"><span class="span1">系统设置</span><i class="fa fa-caret-right"></i><span class="span2">站点设置</span></p>


        <div class="main-list1">
            <p class="main-list-tit">平台名称：</p>
            <input type="text" name="" id="site_name" value="{$config_array.site_name ?? ''}">
        </div>
        <div class="main-list1">
            <p class="main-list-tit">平台域名：</p>
            <input type="text" name="" id="site_domain" value="{$config_array.site_domain ?? ''}">
        </div>

        <div class="main-list1">
            <p class="main-list-tit">技术支持：</p>
            <input type="text" name="" id="site_support_name" value="{$config_array.site_support_name ?? ''}">
        </div>

        <div class="main-list1">
            <p class="main-list-tit">支持链接：</p>
            <input type="text" name="" id="site_user_support" value="{$config_array.site_user_support ?? ''}">
        </div>

        <div class="main-list2">
            <p class="main-list-tit">平台logo：</p>
            <div class="admin-set-upload">
                <div class="upload-img"><img src="{notempty name='$config_array.site_logo'} {$config_array['site_logo']} {else/} __MIMG__/banner.png {/notempty}"></div>
                <p class="lcg-btn5 upload-btn"><input type="file" name="" id="site_logo"><span>上传图片</span></p>
            </div>
        </div>
        <div class="lcg-btn5 admin-set-btn">保存</div>
    </div>
</div>

<!-- 页面加载 -->
<div class="cloud-set-loading" style="display: none;"><i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i></div>

<script src="__JS__/jquery_v3.3.1.js"></script>
<script src="__JS__/layer/layer.js"></script>
<script src="__JS__/common.js"></script>
<script>
    $(function () {
        //是否可进行保存操作
        var json = {
                "site_name": "",
                "site_domain": "",
                "site_support_name": "",
                "site_user_support": "",
                "site_logo": "",
            },
            save_status = 1;

        //平台域名
        $("#site_domain").on("input", function () {
            var site_domain = $(this).val();
            if (!site_domain) {
                layer.msg("平台域名不可为空");
                return false;
            }
            json.site_domain = site_domain;
        }).blur(function () {
            var site_domain = $(this).val();
            var patt = /^http\:\/\/|https\:\/\//;
            if (!site_domain || !patt.test(site_domain)) {
                layer.msg("平台域名必须以http开头");
                save_status = 0;
                return false;
            }
            save_status = 1;
        });
        //平台名称
        $("#site_name").on("input", function () {
            json.site_name = $(this).val();
        });
        //支持链接
        $("#site_user_support").on("input", function () {
            json.site_user_support = $(this).val();
        });
        //技术支持
        $("#site_support_name").on("input", function () {
            json.site_support_name = $(this).val();
        });
        //平台logo图片上传
        $("#site_logo").on("change", function () {
            //图像转Base64
            imgBase64($(this)[0], function (imgString) {
                $(".cloud-set-loading").show();
                $.post("/admin/system/base64Image", {"imgString": imgString}, function (con) {
                    $(".cloud-set-loading").hide();
                    con = $.parseJSON(con);
                    if (con.state == 1) {
                        json.site_logo =  con.url;
                        $(".upload-img > img").prop("src", con.url);
                    } else {
                        layer.msg(con.state);
                    }
                }, 'json');
            });
        });

        //保存按钮
        $('.admin-set-btn').on('click', function () {
            if (save_status === 0) {
                return false;
            }
            save_status = 0;
            $(".cloud-set-loading").show();

            //域名信息


            $.post("/admin/system/setConfig", json, function (result) {
                $(".cloud-set-loading").hide();
                if (result) {
                    layer.msg('保存成功');
                } else {
                    layer.msg('保存失败');
                }
            });
            setTimeout(function () {
                save_status = 1;
            }, 2000);
        });
    });

</script>
</body>
</html>